package org.jsola.hr.helper;

import org.jsola.hr.dto.EmpFamilyAddDTO;
import org.jsola.hr.dto.EmpFamilyUpdateDTO;
import org.jsola.hr.entity.EmpFamilyDO;
import org.jsola.hr.query.EmpFamilyQuery;
import org.jsola.hr.service.IEmpFamilyService;
import org.jsola.hr.vo.EmpFamilyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 员工家庭成员
 *
 * @author zhr
 */
@Component
public class EmpFamilyTestHelper extends BaseTestHelper {
    
    @Autowired
    private EmpInfoTestHelper empInfoTestHelper;
    @Autowired
    private IEmpFamilyService empFamilyService;

    /**
     * 生成add测试数据
     * @return EmpFamilyAddDTO
     */
    public EmpFamilyAddDTO getEmpFamilyAddDTO(){
        EmpFamilyAddDTO empFamilyAddDTO = new EmpFamilyAddDTO();
        empFamilyAddDTO.setEmpId(empInfoTestHelper.saveEmpInfoExample().getId());
        empFamilyAddDTO.setName(getRandomValue("varchar",255));
        empFamilyAddDTO.setRelation(getRandomValue("varchar",255));
        empFamilyAddDTO.setPhone(getRandomValue("varchar",20));
        empFamilyAddDTO.setWorkUnit(getRandomValue("varchar",255));
        empFamilyAddDTO.setCompanyId(getRandomValue("varchar",32));
        return empFamilyAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EmpFamilyUpdateDTO
     */
    public EmpFamilyUpdateDTO getEmpFamilyUpdateDTO(EmpFamilyVO empFamilyVO){
        return empFamilyService.selectDOById(empFamilyVO.getId(), SITE_ID).to(EmpFamilyUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EmpFamilyQuery
     */
    public EmpFamilyQuery getEmpFamilyQuery() {
        EmpFamilyQuery empFamilyQuery = new EmpFamilyQuery();
        List<EmpFamilyDO> empFamilyDOList = empFamilyService.list(new EmpFamilyDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(empFamilyDOList)) {
            EmpFamilyDO empFamilyDO = empFamilyDOList.get(0);
            empFamilyQuery = empFamilyDO.to(EmpFamilyQuery.class);
        }
        return empFamilyQuery;
    }

    /**
     * 保存示例
     * @return EmpFamilyVO
     */
    public EmpFamilyVO saveEmpFamilyExample(){
        EmpFamilyAddDTO addDTO = this.getEmpFamilyAddDTO();
        EmpFamilyVO empFamilyVO = empFamilyService.save(addDTO,buildTokenUser());
        return empFamilyVO;
    }


}

